<?php

App::uses('Sanitize', 'Utility');

class News extends AppModel {
	public $name = "News";
	public $useTable = "news";
	public $order = 'date DESC, id DESC';
	
	public function afterFind($results, $primary = false) {
		foreach($results as &$row) {
			if(isset($row['News'])) {
				$row['News']['slug'] = urlize($row['News']['title']);

				$blurb = html_entity_decode($row['News']['content'], null, 'utf-8');
				$blurb = preg_replace('/<.+?>/', '', $blurb);
				$row['News']['blurb'] = String::truncate($blurb, 100);
				
				$time = strtotime($row['News']['date']);
				$monthName = constant("MONTH_".date("m", $time));
				$row['News']['date_formated'] = sprintf(date("d. \%\s Y", $time), $monthName);
			}
		}
		return $results;
	}
}